/*!
 * @file Texture.cpp
 * @author naoki takeda 
 * @version 1.0
 */
#include "StdAfx.h"
#include <d3d11.h>
#include "src/TextureImpl.h"
#include "src/ManagerImpl.h"

namespace NTEngine {
namespace Graphics {

Texture Texture::create( const char* fileName ) {
	Texture instance;
	instance.m_Impl = NEW Impl( g_ManagerImpl->device(), fileName );
	return instance;
}

Texture Texture::create( int w, int h, bool createMipChain ) {
	Texture instance;
	instance.m_Impl = NEW Impl( g_ManagerImpl->device(), w, h, createMipChain );
	return instance;
}

void Texture::lock( unsigned** buf, int* pitch, int mipLevel ) {
	ASSERT( m_Impl != NULL );
	m_Impl->lock( buf, pitch, mipLevel );
}

void Texture::lock( unsigned** buf, int* pitch, int x, int y, int width, int height, int mipLevel ) {
	ASSERT( m_Impl != NULL );
	m_Impl->lock( buf, pitch, x, y, width, height, mipLevel );
}

void Texture::unlock( unsigned** buf, int mipLevel ) {
	ASSERT( ( *buf != NULL ) && "Graphics::Texture : give LOCKED pointer." );
	ASSERT( m_Impl != NULL );
	m_Impl->unlock( mipLevel );
	*buf = NULL;
}

int Texture::width() const {
	ASSERT( m_Impl != NULL );
	return m_Impl->width();
}

int Texture::height() const {
	ASSERT( m_Impl != NULL );
	return m_Impl->height();
}

int Texture::originalWidth() const {
	ASSERT( m_Impl != NULL );
	return m_Impl->originalWidth();
}

int Texture::originalHeight() const {
	ASSERT( m_Impl != NULL );
	return m_Impl->originalHeight();
}

bool Texture::isReady() {
	ASSERT( m_Impl != NULL );
	return m_Impl->isReady();
}

bool Texture::isError() const {
	ASSERT( m_Impl != NULL );
	return m_Impl->isError();
}

bool Texture::operator<( const Texture& a ) const {
	return ( m_Impl < a.m_Impl );
}

Texture::Texture( const Impl* )
: m_Impl( 0 ) {
}

#define TYPE Texture
#include "NTEngine/Base/Impl/ReferenceTypeTemplate.h"

} // namespace Graphics
} // namespace NTEngine
// EOF